﻿@{
    Layout = null;
}
@using CNKI.TPI.Web.Admin.Model;
@using CNKI.TPI.Web.Base
<script>
    //全选
    function subjectcheckall(e) {
        if ($(e).attr("checked") == "checked") {
            $(".checkboxsubject input[type='checkbox']").each(function () {
                $(this).attr("checked", "checked");
            })
        }
        else {
            $(".checkboxsubject input[type='checkbox']").each(function () {
                $(this).removeAttr("checked", "checked");
            })
        }
    }
    $(".checkboxsubject input[type='checkbox']").click(function () {
        //循环判断列表中的checkbox，如果全部选中则全选框呈勾选状态
        var m = 0;
        if ($(this).attr("checked") != "checked") {
            $("input.subjectall").removeAttr("checked", "checked");
        }
        else {
            $(".checkboxsubject input[type='checkbox']").each(function () {
                if ($(this).attr("checked") != "checked") {
                    m = 1;
                }
            })
            if (m == 1) {
                $("input.subjectall").removeAttr("checked", "checked");
            }
            else {
                $("input.subjectall").attr("checked", "checked");
            }
        }

    })
    //删除 多选
    function delpagelist() {
        var ckbs = $(".checkboxsubject input[type='checkbox']:checked");
        if (ckbs.size() == 0) {
            messageAlert("请选择要删除的记录！");
            return;
        }
        confirmDialog('确定要删除吗?', function () {
            var checkedstr = [];
            ckbs.each(function () {
                checkedstr.push($(this).val());
            })
            var delurl = "@Html.Raw(Url.Action("DeletePageConfig", "Admin_Topic"))";
            var data = { "sysidstr": checkedstr.toString() };
            dealdata(delurl, data);
        })

    }
    //删除
    function delpage(sysid) {
        var delurl = "@Html.Raw(Url.Action("DeletePageConfig", "Admin_Topic"))";
        var data = { "sysidstr": sysid };
        confirmDialog('确定要删除吗?', function () {
            dealdata(delurl, data);
        })
    }
    //调用controll
    function dealdata(urlstr, datastr) {
        $.ajax({
            type: "POST",
            url: urlstr,
            data: datastr,
            success: function (m) {
                if (m == "True") {
                    messageAlert("操作成功！");
                    ajaxLoad('initload', "@Html.Raw(Url.Action("SubjectSetList", "Admin_Topic"))?TopicName=" + escape($("#TopicName").val()) + "&TopicCode=" + $("#TopicCode").val())
                }
                else {
                    messageAlert("操作失败！");
                }
            },
            error: function (e)
            { }
        })
    }

    function dealchecked(checkedsub, checkedparent) {
        var m = 0;
        $(checkedsub).each(function () {
            if ($(this).attr("checked") != "checked") {  //遍历判断是否存在没有选中的记录
                m = 1;
            }
        })
        if (m == 1) {
            $(checkedparent).removeAttr("checked", "checked");
        }
        else {
            $(checkedparent).attr("checked", "checked");
        }
    }
    //添加栏目
    function addpage() {
        ajaxLoad('initload', "@Html.Raw(Url.Action("SubjectSetInfo", "Admin_Topic"))?TopicCode=" + $("#TopicCode").val() + "&TopicName=" + escape($("#TopicName").val()) + "&TopicDB=" + escape($("#TopicDB").val()) + "&SysID=0&DBCode=0")
    }
    function modifypage(sysid, dbcode) {
        ajaxLoad('initload', "@Html.Raw(Url.Action("SubjectSetInfo", "Admin_Topic"))?TopicCode=" + $("#TopicCode").val() + "&TopicName=" + escape($("#TopicName").val()) + "&TopicDB=" + escape($("#TopicDB").val()) + "&SysID=" + sysid + "&DBcode=" + dbcode)
    }
    function backlist() {
        ajaxLoad("initload", '@Html.Raw(Url.Action("SubjectHomePage", "Admin_Topic"))');
    }

    function closeSort() {
        $(".talkDivBg").hide();
        $(".sortMenu").hide();
    }
    function showSort() {
        if ($("#subjectCount").val() > 0) {
            //获取对应的数据
            $.ajax({
                type: "GET",
                url: timestamp("@Html.Raw(Url.Action("GetPageConfig", "Admin_Topic"))"),
                beforeSend: function () { $("#loading").show(); },
                data: { "topiccode": $("#TopicCode").val() },
                success: function (msg) {
                    var obj = eval(msg);
                    $(".ulfield").empty();
                    if (obj != null && obj.length > 0) {
                        for (var i = 0; i < obj.length; i++) {
                            var listr = " <li class=\"f-ct\" style=\"margin-left: 2em;\">  <label class=\"f-label block right\">" +
                           " <input type=\"checkbox\" class=\"f-checkboxR\"  value='" + obj[i].SYSID + "' />" + obj[i].ColumnName + "</label></li>";
                            $(".ulfield").append(listr);
                        }
                    }
                    $("#loading").hide();
                    $(".talkDivBg").show();
                    $(".sortMenu").show();
                },
                error: function (e)
                { $("#loading").hide(); }

            })

           
        }
        else {
            messageAlert("暂无数据，不支持排序！");
        }
    }
    function saveSort() {
        var jsondata = [];
        $('.wrapR-c-box-b-right ul input').each(function (index) {
            var dataobj = {
                "SYSID": $(this).val(),
                "SortNo": index,
            }
            jsondata.push(dataobj);

        })
        var dataold = { "list": jsondata };
        $.ajax({
            type: "POST",
            url: "@Html.Raw(Url.Action("UpdatePageSort", "Admin_Topic"))",
            contentType: "application/json",
            data: JSON.stringify(dataold),
            success: function (msg) {
                if (msg == "True") {
                    closeSort();
                    ajaxLoad('initload', "@Html.Raw(Url.Action("SubjectSetList", "Admin_Topic"))?TopicName=" + escape($("#TopicName").val()) + "&TopicCode=" + $("#TopicCode").val())

                }
                else {
                    messageAlert("操作失败！");
                }
            },
            error: function (e)
            { }
        })

    }
</script>
<input type="hidden" id="subjectCount" value="@ViewBag.Count" />

<table width="100%" cellspacing="0" cellpadding="0" border="0" class="table table-grey">
    <thead>
        <tr class="thead">
            <th class="tdnum">
                <input type="checkbox" class="subjectall" value="" name="" onclick="subjectcheckall(this)">序号</th>
            <th>栏目名称</th>
            <th>来源数据库</th>
            @*<th>显示类型</th>*@
            <th>显示状态</th>
            @*<th>显示位置</th>*@

            <th>操作</th>
        </tr>
    </thead>
    <tbody>
        @{if (ViewBag.PageConfigList != null)
          {
              int sortno = ViewBag.PageSize * (ViewBag.PageNow - 1) + 1;
              foreach (SYS_CMS_TOPIC_PAGECONFIG item in ViewBag.PageConfigList)
              {
                  string str = "even";
                  if (sortno % 2 == 0)
                  {
                      str = "odd";
                  }
            <tr class='@str'>
                <td class="checkboxsubject">
                    <input type="checkbox" value="@item.SYSID">@sortno</td>

                <td>@Html.Raw(@item.ColumnName)</td>
                <td>@item.DBName</td>
                @*<td>
                    @{
                  switch (@item.ShowType)
                  {
                      case 1:
                        @Html.Raw("文章论文");
                                         break;
                      case 2:
                        @Html.Raw("画作");
                                       break;
                      case 3:
                        @Html.Raw("文学作品");
                                         break;
                      case 4:
                        @Html.Raw("焦点图");
                                        break;
                      case 5:
                        @Html.Raw("简介");
                                       break;
                      case 6:
                        @Html.Raw("影音资料");
                                         break;
                      case 7:
                        @Html.Raw("艺术家风采");
                                          break;
                      default:
                                          break;

                  }
                        
                    }

                </td>*@
                <td>
                    @if (@item.IsPub == 0)
                    {
                        @Html.Raw("显示");
                    }
                    else
                    {
                        @Html.Raw("不显示");
                    }</td>
                @*  <td>
                    @if (@item.Location == 0)
                    {
                        @Html.Raw("左侧");
                    }
                    else
                    {
                        @Html.Raw("右侧");
                    }

                </td>*@
                <td class="tc">
                    <a onclick="modifypage('@item.SYSID', '@item.DBCode')" href="javascript:void(0)">编辑</a>
                    <a onclick="delpage('@item.SYSID')" href="javascript:void(0)">删除</a>
                </td>
            </tr>
                    sortno = sortno + 1;
              }
          }

        }
    </tbody>
</table>

@*//分页*@
<div class="pagenav pagenav-02">
    @*上一页*@
    @if (ViewBag.TotalPage > 0)
    {
        if (ViewBag.PageNow != 1)
        {
            int thispage = ViewBag.PageNow - 1;
        <a href="javascript:void(0);" class="page-prev" onclick="searchPageNew('@thispage')" >上一页</a>
        }
        else
        {
        <a href="javascript:return false;" onclick="return false" class="page-prev disable">上一页</a>
        }
@*循环初始化页码*@
        foreach (string numpage in ViewBag.PageList)
        {
            if (numpage != "0")
            {
                int m = int.Parse(numpage);
                if (m == ViewBag.PageNow)
                {
        <a href="javascript:void(0);" class="active" onclick="searchPageNew('@numpage')">@numpage</a>
                    
                }
                else
                {
        <a href="javascript:void(0);" onclick="searchPageNew('@numpage')">@numpage</a>
                }

            }
            else
            {
        <i class="iconfont icon-dian2"></i>
            }

        }
@*下一页*@
        if (ViewBag.TotalPage > 0 && ViewBag.PageNow != ViewBag.TotalPage)
        {
            int nextpage = ViewBag.PageNow + 1;
        <a href="javascript:void(0);" class="page-next" onclick="searchPageNew('@nextpage')" >下一页</a>
        }
        else
        {
        <a href="javascript:return false;" onclick="return false" class="page-prev disable">下一页</a>
        }
    }
    @if (@ViewBag.Count == 0)
    {
        <label>暂无数据！</label>
        
    }
    else
    {
          
        <label>共 </label>
        <label>@ViewBag.Count </label>
        <label>条数据 </label>
    }
</div>
<div class='posr' style="padding-bottom: 20px">

    <a class="btn btn-m btn-submit btn-defa-f" href="javascript:void(0);" onclick="addpage()">添加</a>
    <a onclick="showSort()" class="btn btn-m btn-submit btn-defa-f">排序</a>
    <a class="btn btn-m btn-submit btn-defa-f" href="javascript:void(0);" onclick="delpagelist()">删除</a>
    <a class="btn btn-m btn-prim-f" href="javascript:void(0);" onclick="backlist()">返回</a>

</div>

<div class="talkDivBg" style="display: none; z-index: 999">
    <div class="talkDiv talkDivTr talkW-550 form-h sortMenu" style='margin-top: -278px; display: none'>
        <div class="talkDiv-title">
            <span>排序</span>
            <a class="icon icon-close" title="关闭" href="javascript:void(0);" onclick="closeSort()"><i class="iconfont icon-error3"></i></a>
        </div>
        <div class="talkDiv-body talkDiv-body1">

            <div class="f-gp" style="padding-left: 70px">

                <div class='wrapR-c-box wrapR-c-r wrapR-c-r-l' style="overflow-y: visible; height: 430px">
                    <div class="wrapR-c-box-t">栏目列表</div>
                    <div class="wrapR-c-box-b-right" style="overflow-y: scroll; height: 380px">
                        <ul class="ulfield">
                            @*  @if (ViewBag.PageAll != null)
                                {
                                    foreach (SYS_CMS_TOPIC_PAGECONFIG item in ViewBag.PageAll)
                                    {
                                        if (@item.TopicCode == ViewBag.TopicCode)
                                        {
                                    <li class="f-ct" style="margin-left: 2em;">
                                        <label class="f-label block right">
                                            <input type="checkbox" class="f-checkboxR" value='@item.SYSID' />@item.ColumnName</label>

                                    </li>
                                        }
                                    }
                                }*@
                        </ul>
                    </div>
                </div>

                <div class="wrapR-c-r-r form-h posa" style="top: 80px; left: 400px;">
                    <div>
                        <a title="移至最顶部" onclick=" movefirst(this)" class="iconfont-s iconfont-upest-s"></a>
                        <br />
                        <a title="上移" onclick="moveablove(this)" class="iconfont-s iconfont-up-s"></a>
                        <br />
                        <a title="下移" onclick="movedown(this)" class="iconfont-s iconfont-down-s"></a>
                        <br />
                        <a title="移至最底部" onclick="movelast(this)" class="iconfont-s iconfont-downest-s"></a>
                    </div>


                </div>
            </div>
            <div class="f-gp">
                <div class="f-lb">
                    <label class="f-label"></label>
                </div>
                <div class="f-ct" style="margin-left: 150px">
                    <a href="javascript:void(0);" class="btn btn-m btn-prim-f btn-submit" onclick="saveSort()">保存</a> &#12288;
                </div>
            </div>

        </div>


    </div>
</div>
